<?php

class EnterprisesAdminList extends OrganizationsAbstractList
{

    function __construct()
    {
        parent::__construct( 'enterprise', 50, '',
                array( 'fiscal_id' => 1, 'name' => 1, 'commercial_name' => 1, 'atime' => 1 ) );
    }

    function crear()
    {
        //@TODO: OJO UN ADMIN DE DOS EMPRESAS DIFERENTES APARECERÁ PARA SELECCIONAR LOS ADMINISTRADORES DE PROYECTOS DE UNA EMPRESA LOS USUARIOS DE LA OTRA EMPRESA

        $sql = 'INSERT INTO enterprises ( resource, name, fiscal_id, commercial_name, parent ) VALUES (\'R_ENT\',' . MyLink::quote( $_POST[ 'name' ] ) . ',' . MyLink::quote( $_POST[ 'fiscal_id' ] ) . ',' . MyLink::quote( $_POST[ 'commercial_name' ] ) . ',' . $_SESSION[ 'organization' ] . ')';
        MyLink::$default->execute( $sql );

        $id = MyLink::$default->insert_id;


        Security::addRolEdges( array( 'ADM_ORG' => array( $_SESSION[ 'organization' ] ) ),
                'ADM_ENT', $id );
        Security::addRolEdges( array( 'ADM_ENT' => array( $id ) ), 'USR_ENT',
                $id );

        Security::addPrivilege( 'ADM_ENT', $id, 'R_USR_ORG', $id,
                'EnterpriseUserNot' );
        Security::addPrivilege( 'ADM_ENT', $id, 'R_ADM_ENT', $id,
                'EnterpriseUserAdmin' );

        Security::addPrivileges( 'ADM_ENT', $id, 'R_USR_ENT', $id,
                array( 'EnterpriseUser', 'ProjectUserAdminNot' ) );

        Security::addPrivilege( 'ADM_ENT', $id, 'R_ENT', $id, 'EnterpriseAdmin' );
        Security::addPrivileges( 'USR_ENT', $id, 'R_ENT', $id,
                array( 'Enterprise', 'EnterpriseMain' ) );
    }

}

?>
